# Maintainer: Alexey Pavlov <alexpux@gmail.com>

pkgname=('expat' 'libexpat' 'libexpat-devel')
pkgver=2.2.5
pkgrel=1
pkgdesc="An XML parser library"
arch=('i686' 'x86_64')
url="https://expat.sourceforge.io/"
license=('custom')
source=(https://downloads.sourceforge.net/sourceforge/expat/${pkgname}-${pkgver}.tar.bz2
        msys2-expat-2.1.1.patch)
sha256sums=('d9dc32efba7e74f788fcc4f212a43216fc37cf5f23f4c2339664d473353aedf6'
            '13d38afdceb2892a3ed71836f074d020147d8bd7196e256394b6e0bda29df78e')

prepare() {
  cd ${srcdir}/${pkgname}-${pkgver}
  patch -p1 -i ${srcdir}/msys2-expat-2.1.1.patch
  #rm -f m4/*

  autoreconf -vfi
}

build() {
  cd ${srcdir}/${pkgname}-${pkgver}
  ./configure --prefix=/usr
  make
  make DESTDIR=${srcdir}/dest install
}

check() {
  cd ${srcdir}/${pkgname}-${pkgver}
  make check
}

package_expat() {
  mkdir -p ${pkgdir}/usr/bin
  cp -f ${srcdir}/dest/usr/bin/xml* ${pkgdir}/usr/bin/
  cp -rf ${srcdir}/dest/usr/share ${pkgdir}/usr/
  install -Dm644 ${srcdir}/${pkgname}-${pkgver}/COPYING ${pkgdir}/usr/share/licenses/${pkgname}/COPYING
}

package_libexpat() {
  groups=('libraries')
  depends=('gcc-libs')

  mkdir -p ${pkgdir}/usr/bin
  cp -f ${srcdir}/dest/usr/bin/*.dll ${pkgdir}/usr/bin/
}

package_libexpat-devel() {
  pkgdesc="Libexpat headers and libraries"
  options=('staticlibs')
  groups=('development')
  depends=("libexpat=${pkgver}")

  mkdir -p ${pkgdir}/usr
  cp -rf ${srcdir}/dest/usr/include ${pkgdir}/usr/
  cp -rf ${srcdir}/dest/usr/lib ${pkgdir}/usr/
}
